Skip to content

Conversation

@pcrespov
Copy link
Member

@pcrespov pcrespov commented Sep 26, 2025

What do these changes do?

This PR migrates database interactions in the groups/classifiers and scicrunch modules from aiopg to asyncpg. It introduces a major refactor aimed at clearer separation of concerns, improved repository patterns, and simplified service interfaces.

Key changes include:

  • Moving database logic into dedicated repository classes
  • Introducing service layers instead of direct repository access
  • Updating REST API handlers to rely on these services
  • Streamlining exception handling and error propagation
  • Minor dependency updates

In Detail (by copilot)

Group Classifiers and Scicrunch Resource Refactor:

  • Added GroupClassifierRepository and ScicrunchResourcesRepository classes to encapsulate all database operations for group classifiers and Scicrunch resources, respectively, improving code maintainability and separation of concerns. [1] [2]
  • Refactored the group classifiers service layer (GroupClassifiersService) to use the new repository, and moved logic for determining whether to use static bundles or dynamic RRID trees into this service layer. [1] [2]
  • Updated REST API handlers in groups/_classifiers_rest.py to use service classes (GroupClassifiersService and ScicrunchResourcesService) instead of directly interacting with repositories or legacy service clients, simplifying handler logic and improving error handling. [1] [2] [3] [4] [5]
  • Replaced legacy database connection and query patterns with SQLAlchemy async patterns and explicit error handling, e.g., switching from UniqueViolation to IntegrityError for user-group operations. [1] [2] [3]
  • Updated type annotations and validation logic in models and service methods for better clarity and correctness, including changes to the ClassifierItem model.

Minor improvements and dependency updates:

  • Updated import paths and removed unused legacy imports throughout the affected modules to reflect the new architecture. [1] [2] [3] [4]
  • Added a new faker factory for generating group classifier test data, supporting improved testing of the new repository and service logic.

Related issue/s

How to test

cd services/web/server
make install-dev
pytest -vv tests/unit/**/test_*group*.py
pytest -vv tests/unit/**/test_*scicrunch*.py

Dev-ops

None

@pcrespov pcrespov self-assigned this Sep 26, 2025
@codecov
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

❌ Patch coverage is 51.74129% with 97 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.81%. Comparing base (b24fbf5) to head (af4d430).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8433      +/-   ##
==========================================
+ Coverage   87.11%   87.81%   +0.70%     
==========================================
  Files        1961     1964       +3     
  Lines       76249    76327      +78     
  Branches     1342     1342              
==========================================
+ Hits        66423    67026     +603     
+ Misses       9422     8897     -525     
  Partials      404      404              
Flag Coverage Δ
integrationtests 64.09% <45.77%> (+0.85%) ⬆️
unittests 86.50% <51.24%> (-0.05%) ⬇️
Components Coverage Δ
pkg_aws_library 93.59% <ø> (ø)
pkg_celery_library 83.41% <ø> (ø)
pkg_dask_task_models_library 79.33% <ø> (ø)
pkg_models_library 93.08% <ø> (ø)
pkg_notifications_library 85.20% <ø> (ø)
pkg_postgres_database 87.95% <ø> (ø)
pkg_service_integration 70.19% <ø> (ø)
pkg_service_library 72.55% <ø> (+0.01%) ⬆️
pkg_settings_library 90.19% <ø> (ø)
pkg_simcore_sdk 84.93% <ø> (-0.06%) ⬇️
agent 93.53% <ø> (ø)
api_server 91.94% <ø> (ø)
autoscaling 95.74% <ø> (ø)
catalog 92.36% <ø> (ø)
clusters_keeper 99.13% <ø> (ø)
dask_sidecar 92.38% <ø> (ø)
datcore_adapter 97.94% <ø> (ø)
director 75.81% <ø> (ø)
director_v2 90.83% <ø> (+5.47%) ⬆️
dynamic_scheduler 96.34% <ø> (ø)
dynamic_sidecar 90.43% <ø> (ø)
efs_guardian 89.62% <ø> (ø)
invitations 91.44% <ø> (ø)
payments 92.62% <ø> (ø)
resource_usage_tracker 92.08% <ø> (-0.16%) ⬇️
storage 86.65% <ø> (ø)
webclient ∅ <ø> (∅)
webserver 87.68% <51.74%> (+0.60%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b24fbf5...af4d430. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mergify
Copy link
Contributor

mergify bot commented Sep 26, 2025

🧪 CI Insights

Here's what we observed from your CI run for af4d430.

✅ Passed Jobs With Interesting Signals

Pipeline Job Signal Health on master Retries 🔍 CI Insights 📄 Logs
CI integration-tests Base branch is broken, but the job passed. Looks like this might be a real fix 💪 Broken 0 View View
system-tests Base branch is healthy, but retries were needed. Could be early signs of flakiness 👀 Healthy 1 View View
unit-tests Base branch is healthy, but retries were needed. Could be early signs of flakiness 👀 Healthy 1 View View

@pcrespov pcrespov added the t:maintenance Some planned maintenance work label Sep 29, 2025
@pcrespov pcrespov added this to the Cheops milestone Sep 29, 2025
@pcrespov pcrespov changed the title WIP: ♻️ Is4529/migrate aiopg to asynpg 1 WIP: ♻️ Refactor groups/classifiers and scicrunch to use asyncpg with service/repository separation Sep 29, 2025
@pcrespov pcrespov added a:webserver webserver's codebase. Assigning the area is particularly useful for bugs a:database associated to postgres service and postgres-database package labels Sep 29, 2025
@pcrespov pcrespov force-pushed the is4529/migrate-aiopg-to-asynpg-1 branch from dd3afe1 to eca30ba Compare September 29, 2025 08:28
@pcrespov pcrespov changed the title WIP: ♻️ Refactor groups/classifiers and scicrunch to use asyncpg with service/repository separation ♻️ Refactor groups/classifiers and scicrunch to use asyncpg with service/repository separation Sep 29, 2025
@pcrespov pcrespov marked this pull request as ready for review September 29, 2025 08:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the groups/classifiers and scicrunch modules to migrate from aiopg to asyncpg while introducing a service/repository architectural pattern. The refactor improves separation of concerns by introducing dedicated repository classes for database operations and service layers for business logic.

Key changes include:

  • Introduction of GroupClassifierRepository and ScicrunchResourcesRepository for database operations
  • Creation of service layers (GroupClassifiersService and ScicrunchResourcesService) to handle business logic
  • Migration from aiopg to asyncpg with updated exception handling (UniqueViolationIntegrityError)

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test_groups_classifiers_repository.py New test file for the group classifier repository functionality
test_groups_classifiers.py Removed legacy test file that used aiopg patterns
scicrunch_service.py New service module export for scicrunch functionality
scicrunch/models.py Updated field validation using BeforeValidator instead of field_validator
scicrunch/db.py Removed legacy database access layer using aiopg
scicrunch/_service.py New service layer implementing business logic for scicrunch resources
scicrunch/_repository.py New repository layer for scicrunch database operations using asyncpg
_groups_repository.py Updated exception handling from UniqueViolation to IntegrityError
_classifiers_service.py Refactored to use new repository pattern and service architecture
_classifiers_rest.py Updated REST handlers to use service layers instead of direct repository access
_classifiers_repository.py New repository for group classifier database operations
exporter/_formatter/_sds.py Updated to use new scicrunch service instead of direct repository access
faker_factories.py Added factory function for generating test group classifier data

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@pcrespov pcrespov enabled auto-merge (squash) September 29, 2025 09:05
@pcrespov pcrespov added the 🤖-automerge marks PR as ready to be merged for Mergify label Sep 29, 2025
@pcrespov
Copy link
Member Author

@mergify queue

@mergify
Copy link
Contributor

mergify bot commented Sep 29, 2025

queue

🟠 Waiting for conditions to match

  • -closed [📌 queue requirement]
  • any of: [🔀 queue conditions]
    • all of: [📌 queue conditions of queue default]
      • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
      • #approved-reviews-by >= 2 [🛡 GitHub branch protection]
      • #approved-reviews-by>=2
      • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
      • #changes-requested-reviews-by=0
      • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
      • #review-threads-unresolved=0
      • -conflict
      • -draft
      • base=master
      • label!=🤖-do-not-merge
      • label=🤖-automerge
      • any of: [🛡 GitHub branch protection]
        • check-skipped = deploy to dockerhub
        • check-neutral = deploy to dockerhub
        • check-success = deploy to dockerhub
      • any of: [🛡 GitHub branch protection]
        • check-success = system-tests
        • check-neutral = system-tests
        • check-skipped = system-tests
      • any of: [🛡 GitHub branch protection]
        • check-success = unit-tests
        • check-neutral = unit-tests
        • check-skipped = unit-tests
      • any of: [🛡 GitHub branch protection]
        • check-success = check OAS' are up to date
        • check-neutral = check OAS' are up to date
        • check-skipped = check OAS' are up to date
      • any of: [🛡 GitHub branch protection]
        • check-success = integration-tests
        • check-neutral = integration-tests
        • check-skipped = integration-tests
      • any of: [🛡 GitHub branch protection]
        • check-success = build-test-images (frontend) / build-test-images
        • check-neutral = build-test-images (frontend) / build-test-images
        • check-skipped = build-test-images (frontend) / build-test-images
      • any of: [🛡 GitHub branch protection]
        • check-success = SonarCloud Code Analysis
        • check-neutral = SonarCloud Code Analysis
        • check-skipped = SonarCloud Code Analysis
  • -conflict [📌 queue requirement]
  • -draft [📌 queue requirement]
  • any of: [📌 queue -> configuration change requirements]
    • -mergify-configuration-changed
    • check-success = Configuration changed

Copy link
Contributor

@GitHK GitHK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

@GitHK
Copy link
Contributor

GitHK commented Sep 29, 2025

@pcrespov since you are on this topic, do you mind checking if the tests that check if the integration with scicrunch are still disabled and maybe restore them? Last time I looked they where disabled.

@pcrespov pcrespov force-pushed the is4529/migrate-aiopg-to-asynpg-1 branch from 33a4728 to 4ef0000 Compare September 29, 2025 12:51
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 29, 2025

Quality Gate Passed Quality Gate passed

Issues
0 New issues
1 Accepted issue

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@pcrespov pcrespov disabled auto-merge September 29, 2025 21:16
@pcrespov pcrespov merged commit 15df617 into ITISFoundation:master Sep 29, 2025
142 of 148 checks passed
@pcrespov pcrespov deleted the is4529/migrate-aiopg-to-asynpg-1 branch September 29, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-automerge marks PR as ready to be merged for Mergify a:database associated to postgres service and postgres-database package a:webserver webserver's codebase. Assigning the area is particularly useful for bugs t:maintenance Some planned maintenance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scicurch API seems broken again

4 participants